package com.ssy.lingxi.search.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.search.api.model.request.SimpleIdListRequest;
import com.ssy.lingxi.search.model.response.BrowseRecordResponse;
import com.ssy.lingxi.search.service.IBrowseRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @menu: APP-商城--浏览记录管理
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/9/18
 */
@RestController
@RequestMapping("/search/mobile/shop/browseRecord")
public class MobileBrowseRecordController extends BaseController {

    @Resource
    private IBrowseRecordService browseRecordService;

    /**
     * 查询浏览记录列表
     * @param current 当前页
     * @param pageSize 每页行数
     */
    @RequestMapping(value = "/getBrowseRecordList", method = RequestMethod.GET)
    public Wrapper<PageData<BrowseRecordResponse>> getBrowseRecordList(@RequestParam("current") int current, @RequestParam("pageSize") int pageSize) {
        Long shopId = this.getHeadersShopId();
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(browseRecordService.getBrowseRecordList(sysUser, shopId, current, pageSize));
    }

    /**
     * 删除浏览记录
     * @param simpleIdListRequest 参数
     */
    @RequestMapping(value = "/deleteBrowseRecord", method = RequestMethod.POST)
    public Wrapper<Boolean> deleteBrowseRecord(@RequestBody SimpleIdListRequest simpleIdListRequest){
        Long shopId = this.getHeadersShopId();
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(browseRecordService.deleteBrowseRecord(sysUser, shopId, simpleIdListRequest));
    }

    /**
     * 清空浏览记录
     */
    @RequestMapping(value = "/clearBrowseRecord", method = RequestMethod.POST)
    public Wrapper<Boolean> clearBrowseRecord(){
        Long shopId = this.getHeadersShopId();
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(browseRecordService.clearBrowseRecord(sysUser, shopId));
    }
}
